<template>
	<view>
		<u-navbar title="登录" :autoBack="true" :placeholder="true"></u-navbar>
		<view class="content">
			<view style="display: flex; justify-content: center;">
				<u-image src="@/static/logo.jpg" width="200rpx" height="200rpx" radius="10"></u-image>
			</view>
			<view style="text-align: center;font-size:14px;margin:30px 0;color:#787878;">
				材料数据汇总系统
			</view>
			<u--form :model="form" ref="uForm">
				<u-form-item label="账号:" prop="account" borderBottom>
					<u-input v-model="form.account" type="text" placeholder="请输入账号" clearable />
				</u-form-item>
				<u-form-item label="密码:" prop="password" borderBottom>
					<u-input v-model="form.password" type='password' clearable placeholder="请输入密码" />
				</u-form-item>
				<u-form-item>
					<view style="margin-top: 30px;width: 100%;">
						<u-button @click="submit" type="primary">登录</u-button>
					</view>
				</u-form-item>
			</u--form>

		</view>
		
		<view
			style="width:100%;position: absolute;bottom: 100rpx;left: 0;display: flex;justify-content: center;align-items: center;">
			<view>
				<u-checkbox-group :activeColor='color' v-model="checkboxValue" placement="column">
					<u-checkbox v-for="(item, index) in checkboxList" :key="index" :name="item.name">
					</u-checkbox>
				</u-checkbox-group>
			</view>
			<text>阅读并同意</text>
			<text style="margin:0 10rpx;text-decoration: underline;" :style="{'color':color}"
				@click="toPath('userAgreement')">用户协议</text>
			<text>及</text>
			<text style="margin:0 10rpx;text-decoration: underline;" :style="{'color':color}"
				@click="toPath('privacy')">隐私协议</text>
		</view>
	</view>
</template>

<script>
	let app = getApp();
	export default {
		data() {
			return {
				color: app.globalData.defaultColor,
				form: {
					account: '',
					password: ''
				},
				checkboxValue: [],
				// 基本案列数据
				checkboxList: [{
						name: '同意'
					},

				],
			}
		},
		onLoad() {},
		methods: {
			
			toPath(url) {

				uni.navigateTo({
					url: '/pages/' + url + '/index'
				})
			},
			submit() {
				if (this.checkboxValue[0] !== '同意') {
					uni.$u.toast('请阅读并同意用户及隐私协议!');
					return;
				}
				for (let i in this.form) {
					if (!this.form[i]) {
						uni.$u.toast('请填写账号密码!');
						return;
					}
				}
				let params = {
					username: this.form.account,
					password: this.form.password,
					loading: true
				}

				uni.$u.http.post('/user/login', params).then(res => {
					this.loading = false;
					if (res.userName) {
						uni.setStorageSync('userName', res.userName)
					}
					if (res.phoneNum) {
						uni.setStorageSync('phoneNum', res.phoneNum)
					}
					if (res.userId) {
						uni.setStorageSync('userId', res.userId)
					}
					if (res.token) {
						uni.setStorageSync('token', res.token)
					}
					if (res.password) {
						uni.setStorageSync('password', res.password)
					}
					 uni.switchTab({
					 	url:'/pages/index/index'
					 })
				}).catch(err => {

				})
			}
		},
	}
</script>

<style lang="scss" scoped>
	.content {
		position: absolute;
		width: 80%;
		top: 20%;
		left: 50%;
		transform: translate(-50%, 0);
	}
</style>